<template>
  <div class="info">
    <div class="info-title"><span class="info-title-icon"></span>养户信息</div>
    <div class="info-content">
      <div class="info-content-item">
        <svgIcon name="rearername" width="50px" height="50px"></svgIcon>
        <div class="right">
          <div class="label">养户姓名</div>
          <div class="value">
            {{ formData.rearerName || '-' }}
          </div>
        </div>
      </div>
      <div class="info-content-item">
        <svgIcon name="contact" width="50px" height="50px"></svgIcon>
        <div class="right">
          <div class="label">联系方式</div>
          <div class="value">
            {{ formData.phone || '-' }}
          </div>
        </div>
      </div>
      <div class="info-content-item">
        <svgIcon name="company" width="50px" height="50px"></svgIcon>
        <div class="right">
          <div class="label">公司</div>
          <div class="value">
            {{ formData.company || '-' }}
          </div>
        </div>
      </div>
      <div class="info-content-item">
        <svgIcon name="service" width="50px" height="50px"></svgIcon>
        <div class="right">
          <div class="label">服务部</div>
          <div class="value">
            {{ formData.orgName || '-' }}
          </div>
        </div>
      </div>
      <div class="info-content-item">
        <svgIcon name="admin" width="50px" height="50px"></svgIcon>
        <div class="right">
          <div class="label">直属管理员</div>
          <div class="value">
            {{ formData.tech || '-' }}
          </div>
        </div>
      </div>
      <div class="info-content-item">
        <svgIcon name="address" width="50px" height="50px"></svgIcon>
        <div class="right">
          <div class="label">养户地址</div>
          <div class="value">
            {{ formData.address || '-' }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, ref, watch } from 'vue'
import { getRearerInfo } from '@/api/api'

const formData: any = ref({})
const props = defineProps({
  rearerId: {
    type: String,
    default: ''
  }
})

watch(
  () => props.rearerId,
  (newValue, oldValue) => {
    if (newValue) {
      fetchRearerInfo()
    }
  },
  { immediate: true }
)

// 获取养户信息
const fetchRearerInfo = async () => {
  try {
    const res = await getRearerInfo({
      rearerId: props.rearerId
    })
    if (res && res.data) {
      formData.value = res.data
    }
  } catch (error) {
    console.error('获取养户信息失败:', error)
  }
}
</script>

<style scoped lang="scss">
.info {
  &-title {
    padding: 10px 0 20px;
    font-weight: bold;
    font-size: 14px;
    display: flex;
    align-items: center;
    &-icon {
      display: block;
      width: 5px;
      height: 16px;
      background-color: #409dfd;
      margin-right: 10px;
    }
  }

  &-content {
    padding: 15px 0 0;
    width: 100%;
    display: flex;
    flex-wrap: wrap;

    &-item {
      width: 33.33%;
      margin-bottom: 20px;
      display: flex;
      .right {
        margin-left: 20px;
        line-height: 30px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
      }
    }
  }
}
</style>
